﻿//
// Name: usbDevice.cs
// Project: elektor HiD Temperature Modul
// Author: Michael Odenwald
// Creation Date: 10.05.2013 
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using usbGenericHidCommunications;
using System.Diagnostics;

namespace WindowsApp
{
    /// <summary>
    /// This is the implementation of the usbDevice with his service methodes based on the
    /// usbGenericHidCommunication Class
    /// </summary>
    class usbDevice : usbGenericHidCommunication
    {
        private int tval;

        /// <summary>
        /// Class constructor - place any initialisation here
        /// </summary>
        /// <param name="vid"></param>
        /// <param name="pid"></param>
        public usbDevice(int vid, int pid)
            : base(vid, pid)
        {
        }

        /// <summary>
        /// USB HiD Temperatur Modul Methode GetTemeratur()
        /// </summary>
        public int GetTemperatur()
        {
            // Declare a input buffer
            Byte[] inputBuffer = new Byte[5]; // we expect 5 byte; 1 x ReportID and 4 Byte temperature

            inputBuffer[0] = 10; // Read ReportID 10

            // Perform the Read Command
            bool success;
            success = getFeatureReport(inputBuffer);

            if (success == false)
            {
                Debug.WriteLine("Error during getFeatureReport");
                return tval;  // Error during USB HiD_GetFeature Request so return the old value
            }

            tval  = inputBuffer[1] << 24;
			tval |= inputBuffer[2] << 16;
			tval |= inputBuffer[3] << 8;
			tval |= inputBuffer[4];		

            return tval; // Return the new value
        }
    }
}
